package com.yanqu.xiuxian.crosssystem.manger.elementalbonds.data;

import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.entity.ElementalBondsBlock;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ElementalBondsGameData {

    private int sceneId;

    private List<List<ElementalBondsBlock>> blockList;

    // 格子边框    key：y，x
    private Map<Integer, Map<Integer, ElementalBondsBlock>> frameMap = new ConcurrentHashMap<>();

    // 计数
    private int scene05Count;
    private int scene12Color;
    private int scene12Score;
    private int scene13Count;
    private int scene04Count;
    private int scene08Count;
    private int scene07Count;
    private List<ElementalBondsBlock> scene07StageBoxList = new ArrayList<>();

    public ElementalBondsGameData() {
    }

    public ElementalBondsGameData(int sceneId, List<List<ElementalBondsBlock>> blockList) {
        this.sceneId = sceneId;
        this.blockList = blockList;
    }

    public ElementalBondsGameData(int sceneId, List<List<ElementalBondsBlock>> blockList, Map<Integer, Map<Integer, ElementalBondsBlock>> frameMap,
                                  int scene05Count, int scene12Color, int scene12Score, int scene13Count, int scene04Count, int scene08Count, int scene07Count,
                                  List<ElementalBondsBlock> scene07StageBoxList) {
        this.sceneId = sceneId;
        this.blockList = blockList;
        this.frameMap = frameMap;
        this.scene05Count = scene05Count;
        this.scene12Color = scene12Color;
        this.scene12Score = scene12Score;
        this.scene13Count = scene13Count;
        this.scene04Count = scene04Count;
        this.scene08Count = scene08Count;
        this.scene07Count = scene07Count;
        this.scene07StageBoxList = scene07StageBoxList;
    }

    public ElementalBondsGameData clone() {
        int cloneSceneId = this.sceneId;
        List<List<ElementalBondsBlock>> cloneBlockList = new ArrayList<>();
        for (List<ElementalBondsBlock> elementalBondsBlockList : this.blockList) {
            List<ElementalBondsBlock> cloneElementalBondsBlockList = new ArrayList<>();
            for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlockList) {
                cloneElementalBondsBlockList.add(elementalBondsBlock.clone());
            }
            cloneBlockList.add(cloneElementalBondsBlockList);
        }

        Map<Integer, Map<Integer, ElementalBondsBlock>> cloneFrameMap = new ConcurrentHashMap<>();
        for (Map<Integer, ElementalBondsBlock> elementalBondsBlockMap : this.frameMap.values()) {
            for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlockMap.values()) {
                cloneFrameMap.putIfAbsent(elementalBondsBlock.getY(), new ConcurrentHashMap<>());
                cloneFrameMap.get(elementalBondsBlock.getY()).put(elementalBondsBlock.getX(), elementalBondsBlock.clone());
            }
        }
        int cloneScene05Count = this.scene05Count;
        int cloneScene12Color = this.scene12Color;
        int cloneScene12Score = this.scene12Score;
        int cloneScene13Count = this.scene13Count;
        int cloneScene04Count = this.scene04Count;
        int cloneScene08Count = this.scene08Count;
        int cloneScene07Count = this.scene07Count;

        List<ElementalBondsBlock> cloneScene07StageBoxList = new ArrayList<>();
        for (ElementalBondsBlock elementalBondsBlock : this.scene07StageBoxList) {
            cloneScene07StageBoxList.add(elementalBondsBlock.clone());
        }
        return new ElementalBondsGameData(cloneSceneId, cloneBlockList, cloneFrameMap, cloneScene05Count, cloneScene12Color,
                cloneScene12Score, cloneScene13Count, cloneScene04Count, cloneScene08Count, cloneScene07Count, cloneScene07StageBoxList);
    }

    public static ElementalBondsGameData createElementalBondsGameData(int appointSceneId, List<List<ElementalBondsBlock>> blockList) {
        ElementalBondsGameData elementalBondsGameData = new ElementalBondsGameData();
        elementalBondsGameData.setSceneId(appointSceneId);
        elementalBondsGameData.setBlockList(blockList);
        return elementalBondsGameData;
    }

    public void addFrame(ElementalBondsBlock elementalBondsBlock) {
        frameMap.putIfAbsent(elementalBondsBlock.getY(), new ConcurrentHashMap<>());
        frameMap.get(elementalBondsBlock.getY()).put(elementalBondsBlock.getX(), elementalBondsBlock);
    }

    public int getSceneId() {
        return sceneId;
    }

    public void setSceneId(int sceneId) {
        this.sceneId = sceneId;
    }

    public List<List<ElementalBondsBlock>> getBlockList() {
        return blockList;
    }

    public void setBlockList(List<List<ElementalBondsBlock>> blockList) {
        this.blockList = blockList;
    }

    public Map<Integer, Map<Integer, ElementalBondsBlock>> getFrameMap() {
        return frameMap;
    }

    public void setFrameMap(Map<Integer, Map<Integer, ElementalBondsBlock>> frameMap) {
        this.frameMap = frameMap;
    }

    public int getScene05Count() {
        return scene05Count;
    }

    public void setScene05Count(int scene05Count) {
        this.scene05Count = scene05Count;
    }

    public int getScene12Color() {
        return scene12Color;
    }

    public void setScene12Color(int scene12Color) {
        this.scene12Color = scene12Color;
    }

    public int getScene12Score() {
        return scene12Score;
    }

    public void setScene12Score(int scene12Score) {
        this.scene12Score = scene12Score;
    }

    public int getScene13Count() {
        return scene13Count;
    }

    public void setScene13Count(int scene13Count) {
        this.scene13Count = scene13Count;
    }

    public int getScene04Count() {
        return scene04Count;
    }

    public void setScene04Count(int scene04Count) {
        this.scene04Count = scene04Count;
    }

    public int getScene08Count() {
        return scene08Count;
    }

    public void setScene08Count(int scene08Count) {
        this.scene08Count = scene08Count;
    }

    public int getScene07Count() {
        return scene07Count;
    }

    public void setScene07Count(int scene07Count) {
        this.scene07Count = scene07Count;
    }

    public List<ElementalBondsBlock> getScene07StageBoxList() {
        return scene07StageBoxList;
    }

    public void setScene07StageBoxList(List<ElementalBondsBlock> scene07StageBoxList) {
        this.scene07StageBoxList = scene07StageBoxList;
    }

}
